package models
{
    import com.pamakids.models.BaseVO;
    import com.pamakids.utils.CloneUtil;
    
    public class PraiseVO extends BaseVO
    {
        public function PraiseVO()
        {
            super();
        }
        
        public var author:UserVO //用户对象	{nickname:昵称,portrait:头像,_id:用户id}
        public var target:UserVO;
        public var type:int;
        
        public var atBodies:Array;
        
        public var subType:int;
        public var data:Object;
        public var length:uint;
//		public var created_at:Date //赞的时间	
        
        public static function convertPraiseVO(o:Object):PraiseVO
        {
            var user:UserVO=CloneUtil.convertObject(o.user, UserVO);
            if(o.atBodies)
                o.atBodies=o.atBodies.map(function(item:*, index:int, array:Array):Object{
                    if(item is String)
                    {
                        var arr:Array=item.split(',');
                        if(arr[0].length>24&&arr.length==1)
                            return {_id:arr[0].substr(0,24),nickname:arr[0].substr(25)};
                        else
                            return {_id:arr[0],nickname:arr[1]};
                    }
                    else
                        return {_id: item.id, nickname: item.nickname};
                });
            o.target=CloneUtil.convertObject(o.target, UserVO);
            var pv:PraiseVO=CloneUtil.convertObject(o, PraiseVO);
            pv.author=user;
            return pv;
        }
    }
}


